-
Notifications
You must be signed in to change notification settings - Fork 189
ENT-6193, CFE-3421: Added policy function classfilterdata() #5836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
larsewi
commented
Jul 3, 2025
- Added policy function classfilterdata()
- Added acceptance tests for classfilterdata
Ticket: ENT-6193, CFE-3421 Changelog: Title Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
@cf-bottom jenkins, please |
Edit: This build is green, but parts of it was not run (DTs). Sure, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/12330/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-12330/ |
@cf-bottom please build in Jenkins again :) |
Sure, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/12354/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-12354/ |
tests/acceptance/01_vars/02_functions/classfilterdata_array_of_objects_foo.cf
Outdated
Show resolved
Hide resolved
tests/acceptance/01_vars/02_functions/classfilterdata_array_of_objects_foo_bar.cf
Outdated
Show resolved
Hide resolved
tests/acceptance/01_vars/02_functions/classfilterdata_array_of_objects_foo.cf
Outdated
Show resolved
Hide resolved
tests/acceptance/01_vars/02_functions/classfilterdata_array_of_objects_foo_bar.cf
Outdated
Show resolved
Hide resolved
Ticket: ENT-10961, CFE-1840 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
"expected[0]" | ||
string => storejson('[ | ||
{ "key_0": "foo", "key_1": "!foo", "key_2": "foo&bar", "key_3": "foo|bar" }, | ||
{ "key_0": "bar", "key_1": "!bar", "key_2": "bar&baz", "key_3": "bar|baz" }, | ||
]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this whole test would be a lot easier to read (and verify that it's correct) if you did it in a more simple way - calling another bundle, using expandrange, etc. is really not necessary AFAICT. i.e.
vars:
"data"
data => '[
{ "key_0": "foo", "key_1": "!foo", "key_2": "foo&bar", "key_3": "foo|bar" },
{ "key_0": "bar", "key_1": "!bar", "key_2": "bar&baz", "key_3": "bar|baz" },
{ "key_0": "baz", "key_1": "!baz", "key_2": "foo&baz", "key_3": "foo|baz" },
]';
# Explain the test case:
"expected[0]"
string => storejson('[
{ "key_0": "foo", "key_1": "!foo", "key_2": "foo&bar", "key_3": "foo|bar" },
{ "key_0": "bar", "key_1": "!bar", "key_2": "bar&baz", "key_3": "bar|baz" },
]');
"actual[0]"
data => classfilterdata("@(data)", "array_of_objects", "key_0");
# Check that actual[0] == expected[0]
foo
and bar
could also be replaced by classes which make it easier to read the data / test case, i.e.:
classes:
"class_exists";
# "class_missing";
(or true
/ false
).
size_t index = strtoul(class_expr_index, &endptr, 10); | ||
if (!StringEqual(endptr, "")) /* check that the whole string was consumed */ | ||
{ | ||
Log(LOG_LEVEL_VERBOSE, | ||
"Function %s(): Bad class expression index '%s': Not a valid integer", | ||
fn_name, class_expr_index); | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have some functions for this StringToLong
and StringToUnsignedLong
maybe, did you check if you can use them?
for (size_t i = JsonLength(parent); i > 0; i--) | ||
{ | ||
size_t index = i - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this could easily turn into an off-by-one error, I'd consider being more explicit;
for (size_t i = JsonLength(parent); i > 0; i--) | |
{ | |
size_t index = i - 1; | |
for (size_t index_plus_one = JsonLength(parent); index_plus_one > 0; index_plus_one--) | |
{ | |
size_t index = index_plus_one - 1; |
@cf-bottom jenkins, please |
Lars had already done a rebuild so I cancelled tom's build and s/12359/12358/ here. Jenkins: https://ci.cfengine.com/job/pr-pipeline/12358/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-12358/ |